const tesseract = require('node-tesseract'),
log = require('../util/log');

var imgs = [{
		name: '0.tif',
		value: 'KeRf'
	}, {
		name: '1.tif',
		value: 'gAnS'
	}, {
		name: '2.tif',
		value: 'ZQq8'
	}, {
		name: '3.tif',
		value: 'ofE7'
	}, {
		name: '4.tif',
		value: 'OPjv'
	}, {
		name: '5.tif',
		value: 'wKM3'
	}, {
		name: '6.tif',
		value: 'EmrZ'
	}
],
promiseList = [];
imgs.forEach(item => {
	promiseList.push(new Promise(resolve => {
			tesseract.process('../../tesseract/' + item.name, {
				l: 'cgs'
			}, (err, text) => {
				if (err) {
					log(err)
					return
				}
				resolve(text.replace(/[\r\n\s]/gm, ''))
			})
		}))
})
Promise.all(promiseList).then(result => {
	var rightNum = 0;
	imgs.forEach((item, i) => {
		log(item.value + ' ' + result[i])
		if (item.value == result[i])
			rightNum++
	})
	log('正确率：' + (rightNum / imgs.length))
})
